//
//  UIBarButtonItem+Extensin.swift
//  WHSinaWeiBo
//
//  Created by 王寒 on 16/4/8.
//  Copyright © 2016年 wanghan. All rights reserved.
//

import UIKit

extension UIBarButtonItem{


    
    convenience init(imageName: String?,title: String?,target: AnyObject,action: Selector){
     
        self.init()
        
        let btn = UIButton()
        
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if let imgName = imageName{
            btn.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
            btn.setImage(UIImage(named: "\(imgName)_highlighted"), forState: UIControlState.Highlighted)
        }
        
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        //设置btn大小
        btn.sizeToFit()
        customView = btn
    }
    
    
    
    
}
/*

     UIBarButtonItem(image: <#T##UIImage?#>, style: <#T##UIBarButtonItemStyle#>, target: <#T##AnyObject?#>, action: <#T##Selector#>)
*/